
import proFetch from '../../../public/functions/project-fetch';

export default {
    data: {
        context: {},
        language: {},
        pageIns: null,
        currentTreeData: '',// 左树当前选中的
        activeTab: 'role',// 右侧表格tab当前选中的
        editing: false,// 是否处于分配状态
        roleData: {rows: []}, // 获取的总数据
        userData: {rows: []},
        roleCheckedList: [],// 角色选中项
        roleUnCheckedList: [],// 角色未选中项
        userCheckedList: [],// 用户选中项
        userUnCheckedList: [],
        rolePageInfo: {
            pageIndex: 1,
            pageSize: 10,
            total: 0,
            totalPage: 1
        }, // 主页面表格的分页信息
        userPageInfo:{
            pageIndex: 1,
            pageSize: 10,
            total: 0,
            totalPage: 1
        }, // 主页面表格的分页信息
        searchValue: '',
        roleSearchData: {},
        userSearchData: {},
        assignedRole: [], // 保存初始得到的已分配的数据
        assignedUser: []
    },
    sync: {
        update: (state, payload) => {
            return {
                ...state,
                ...payload
            }
        }
    },
    async: {
        getTreeData(dispatch, getState, payload) {
            let state = getState()['reportAss'];
            let postData = {};

            if(state.orgValue) {
                postData['pk_org'] = state.orgValue.refpk;
            }
            if(payload.orgValue) {
                postData['pk_org'] = payload.orgValue.refpk;
            }

            return proFetch({
                url: '/nccloud/hrhi/repauth/RptauthTreeQueryAction.do',
                body: postData
            });
        },
        getMainTableData(dispatch, getState, payload) {
            let state = getState()['reportAss'];
            let postData = {
                pk_rpt_def: payload.currentTreeData ? payload.currentTreeData : state.currentTreeData,
                pageInfo:payload.pageInfo ? payload.pageInfo : state.rolePageInfo,
            };

            if(state.orgValue || payload.orgValue) {
                postData['pk_org'] = payload.orgValue ? payload.orgValue.refpk : state.orgValue.refpk;
            }
            if(payload.searchWord!== ''){
                postData['searchWord'] = payload.searchWord
            }
            if(payload.index !== -1){
                postData['index'] = payload.index
            }
            return proFetch({
                url: '/nccloud/hrhi/repauth/RptauthTreeSelectAction.do',
                body: postData
            });
        },
        saveAssignment(dispatch, getState, payload) {
            return proFetch({
                url: '/nccloud/hrhi/repauth/RptauthSaveAction.do',
                body: payload.postData
            });
        },
        checkAssignment(dispatch, getState, payload) {
            let state = getState()['reportAss'];

            let postData = {
                pk_rpt_def: payload.currentTreeData ? payload.currentTreeData : state.currentTreeData
            };

            if(state.orgValue) {
                postData['pk_org'] = state.orgValue.refpk;
            }
            return proFetch({
                url: '/nccloud/hrhi/repauth/RptauthAuthAction.do',
                body: postData
            });
        }
    }
};